package com.beiming.moudle.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.beiming.moudle.auth.dao.ProInfoDao;
import com.beiming.moudle.auth.entity.BussEntity;
import com.beiming.moudle.auth.entity.CustomerEntity;
import com.beiming.moudle.auth.entity.ProductInfoEntity;
import com.beiming.moudle.auth.entity.UserEntity;
import com.beiming.moudle.auth.entity.utillClass.ProInfoPage;
import com.beiming.moudle.auth.service.ProInfoService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProInfoServiceImpl extends ServiceImpl<ProInfoDao,ProductInfoEntity> implements ProInfoService {

   @Autowired
   private ProInfoDao proInfoDao;
    @Override
    public IPage<ProductInfoEntity> getMsgPage(ProInfoPage proInfoPage) {
        LambdaQueryWrapper<ProductInfoEntity> lqw = new LambdaQueryWrapper<>();
        lqw.like(null!=(proInfoPage.getBussinessId()),ProductInfoEntity::getBussinessId,proInfoPage.getBussinessId());
        lqw.like(Strings.isNotEmpty(proInfoPage.getProductCore()),ProductInfoEntity::getProductCore,proInfoPage.getProductCore());
        lqw.like(Strings.isNotEmpty(proInfoPage.getProductName()),ProductInfoEntity::getProductName,proInfoPage.getProductName());
        IPage pag = new Page(proInfoPage.getCurrentPage(),proInfoPage.getPageSize());
        proInfoDao.selectPage(pag,lqw);
        return pag;
    }
    public IPage<ProductInfoEntity> getPage(ProInfoPage proInfoPage) {
        LambdaQueryWrapper<ProductInfoEntity> lqw = new LambdaQueryWrapper<>();
        lqw.eq(null!=(proInfoPage.getCategoryId()),ProductInfoEntity::getTwoCategoryId,proInfoPage.getCategoryId());
        IPage pag = new Page(proInfoPage.getCurrentPage(),proInfoPage.getPageSize());
        proInfoDao.selectPage(pag,lqw);
        return pag;
    }
    @Override
    public int updateProStatus(ProductInfoEntity productInfoEntity) {
        return  proInfoDao.updateById(productInfoEntity);
    }

    @Override
    public String getProName(int id) {
        QueryWrapper<ProductInfoEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("product_id",id);
        ProductInfoEntity productInfoEntity=  proInfoDao.selectOne(queryWrapper);
        return productInfoEntity.getProductName();
    }

    @Override
    public int addProduct(ProductInfoEntity productInfoEntity) {

        return proInfoDao.insert(productInfoEntity);
    }

    @Override
    public ProductInfoEntity getProduct(int id) {
        QueryWrapper<ProductInfoEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("product_id",id);
        ProductInfoEntity productInfoEntity=  proInfoDao.selectOne(queryWrapper);
        return productInfoEntity;
    }
}
